<script setup>
import { searchIDgoods } from '/src/api/layout.js'
import { ref } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()
const needdata = ref([])
const can = ref(true)
const searchGoods = async (categoryId) => {
  console.log(categoryId)
  const res = await searchIDgoods(categoryId, params.value)
  console.log(res.data)
  needdata.value = res.data.records.slice(0, 6)
  console.log(needdata.value.length)
}
const params = ref({
  pageNum: 1,
  pageSize: 10
})
const getdata = (id) => {
  searchGoods(id)
}
defineProps({
  data: {},
  ndata: {}
})
</script>
<template>
  <div class="home-category">
    <ul class="menu">
      <li
        v-for="item2 in data"
        :key="item2.id"
        @mouseenter="getdata(item2.id), (can = false)"
        @mouseleave="can = true"
        @click="router.push('/goods/channel')"
      >
        <span>{{ item2.name }}</span>
        <!-- 弹层layer位置 -->
        <div class="seew" v-if="can">
          <h4>至尊精品</h4>
          <el-carousel>
            <el-carousel-item v-for="item in ndata" :key="item">
              <!-- <h3 class="small justify-center" text="2xl">{{ item }}</h3> -->
              <img :src="item.image" alt="" />
            </el-carousel-item>
          </el-carousel>
        </div>
        <div class="layer">
          <h4>分类最新 <small>当前最新的几件商品</small></h4>
          <ul>
            <li v-for="item in needdata" :key="item.id">
              <a
                :href="`/goods/detail/${item.id}`"
                target="_blank"
                rel="noopener noreferrer"
              >
                <img :src="item.image" />
                <div class="info">
                  <i class="name ellipsis-2">当前分类{{ item2.name }}</i>
                  <i class="desc ellipsis">名称{{ item.name }}</i>
                  <i class="price">￥{{ item.price }}</i>
                </div>
              </a>
            </li>
            <el-empty
              v-if="needdata.length == 0"
              description="暂无"
              style="margin: auto"
            />
          </ul>
        </div>
      </li>
    </ul>
  </div>
</template>
<style scoped lang="scss">
.home-category {
  width: 250px;
  height: 500px;
  background: gray;
  position: relative;
  z-index: 99;
  left: 5%;

  .menu {
    li {
      padding-left: 40px;
      height: 55px;
      line-height: 55px;

      &:hover {
        background: #00be9a;
      }

      span {
        color: #fff;
        &:first-child {
          font-size: 16px;
        }
      }
      .seew {
        width: 990px;
        height: 500px;
        background: rgba(255, 255, 255, 0.8);
        position: absolute;
        left: 250px;
        top: 0;
        display: block;
        float: left;
        padding: 0 15px;
        h4 {
          font-size: 20px;
          font-weight: normal;
          line-height: 80px;
        }
      }
      .layer {
        width: 990px;
        height: 500px;
        background: rgba(255, 255, 255, 0.8);
        position: absolute;
        left: 250px;
        top: 0;
        display: none;
        padding: 0 15px;
        i {
          margin-right: 20px;
        }
        h4 {
          font-size: 20px;
          font-weight: normal;
          line-height: 80px;

          small {
            font-size: 16px;
            color: #666;
          }
        }

        ul {
          display: flex;
          flex-wrap: wrap;

          li {
            width: 310px;
            height: 120px;
            margin-right: 15px;
            margin-bottom: 15px;
            border: 1px solid #eee;
            border-radius: 4px;
            background: #fff;

            &:nth-child(3n) {
              margin-right: 0;
            }

            a {
              display: flex;
              width: 100%;
              height: 100%;
              align-items: center;
              padding: 10px;

              :hover {
                background: #e3f9f4;
              }

              img {
                width: 95px;
                height: 95px;
              }

              .info {
                padding-left: 10px;
                line-height: 24px;
                overflow: hidden;

                .name {
                  font-size: 16px;
                  color: #666;
                }

                .desc {
                  color: #999;
                }

                .price {
                  font-size: 22px;
                  color: red;

                  i {
                    font-size: 16px;
                  }
                }
              }
            }
          }
        }
      }
      // 关键样式  hover状态下的layer盒子变成block
      &:hover {
        .layer {
          display: block;
        }
      }
    }
  }
}
</style>
